//
//  HMStatusToolBar.swift
//  Black22
//
//  Created by Apple on 16/11/22.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

//  首页toolBar工具条
class HMStatusToolBar: UIView {

    fileprivate lazy var retweetButton: UIButton = self.addChildButton(imageName: "timeline_icon_retweet", title: "转发")
    fileprivate lazy var commentButton: UIButton = self.addChildButton(imageName: "timeline_icon_comment", title: "评论")
    fileprivate lazy var unLikeButton: UIButton = self.addChildButton(imageName: "timeline_icon_unlike", title: "赞")
    
    var statusViewModel: HMStatusViewModel? {
        didSet {
            retweetButton.setTitle(statusViewModel?.retweetCountString, for: .normal)
            commentButton.setTitle(statusViewModel?.commentCountString, for: .normal)
            unLikeButton.setTitle(statusViewModel?.unLikeCountString, for: .normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        
        retweetButton.snp_makeConstraints { (make) in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp_makeConstraints { (make) in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(retweetButton)
            make.bottom.equalTo(retweetButton)
            make.width.equalTo(unLikeButton)
        }
        unLikeButton.snp_makeConstraints { (make) in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        
        let firstLineView = addLineView()
        let secondLineView = addLineView()
        firstLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        secondLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        
    }
    
    //  添加子线视图
    fileprivate func addLineView() -> UIImageView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }
    
    
    //  添加子按钮
    fileprivate func addChildButton(imageName: String, title: String) -> UIButton {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), for: .normal)
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        button.adjustsImageWhenHighlighted = false
        addSubview(button)
        return button
    }
    
    
    
    

}
